﻿#include "widget.h"
#include "ui_widget.h"

Helper::Helper(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    journal=new Journal(this);
    ui->tabWidget->addTab(journal,CAT_JOURNAL);

    purchaseLog=nullptr;
    receipt=nullptr;
    macWhiteList=nullptr;

    initializeWidgets();
}

Helper::~Helper()
{
    delete ui;
}

void Helper::initializeWidgets()
{
    auto memo=new ItemWidget(this,TD_JOURNAL,CAT_MEMO);
    auto schedule=new ItemWidget(this,TD_JOURNAL,CAT_SCHEDULE);
    ui->tabWidget->addTab(memo,CAT_MEMO);
    ui->tabWidget->addTab(schedule,CAT_SCHEDULE);

    auto items=sp_getCategory(TD_JOURNAL);
    if(items.size() > 0)
    {
        if(items.contains(CAT_JOURNAL))
            items.removeOne(CAT_JOURNAL);

        if(items.contains(CAT_MEMO))
            items.removeOne(CAT_MEMO);

        if(items.contains(CAT_SCHEDULE))
            items.removeOne(CAT_SCHEDULE);

        foreach (auto item, items) {
            auto itemWidget=new ItemWidget(this,TD_JOURNAL,item);
            ui->tabWidget->addTab(itemWidget,item);
        }
    }
}

void Helper::closeEvent(QCloseEvent *)
{
    showMinimized();
}

void Helper::on_btn_pruchaseLog_clicked()
{
    if(purchaseLog == nullptr)
        purchaseLog=new PurchaseLog;
    purchaseLog->show();
}

void Helper::on_btn_macWhiteList_clicked()
{
    if(macWhiteList == nullptr)
        macWhiteList=new MacWhiteList;
    macWhiteList->show();
}

void Helper::on_btn_receipt_clicked()
{
    if(receipt == nullptr)
        receipt = new Receipt;
    receipt->show();
}
